<template>
	<view>
		<div v-if="type == '下拉'">
			<input v-model="data_value" disabled="true" @click="inputalert"/>
		</div>
		<div v-else-if="type == '文本'">
			<input v-model="data_value" @input="text_value" />
		</div>
		<div v-else-if="type == '小数' || type == '整数'">
			<input v-model="data_value" @input="text_value" type="number"/>
		</div>
		<div v-else-if="type == '日期' || type == '时间'">
			<kxTime :date='data_value' :start='1' @rundata='datetime' :default_time='1'></kxTime>
		</div>
		<div v-else-if="type == '搜索选择'">
			<input v-model="data_value" disabled="true" @click="inputserch"/>
		</div>
		<div v-else-if="type == '区块'">
			<textarea style="border: 1px solid #cacaca; width: 200px; margin: 15rpx 0 0 15rpx; border-radius: 4px;padding: 0 0 0 15rpx;height: 50rpx;" 
			cursor-spacing="-20" 
			v-model="data_value" 
			@input="text_value"
			></textarea>
		</div>
		<div v-else-if="type == '是否'">
			<radio-group @change="radioTrue"  style="transform:scale(0.7);">
				 <radio value="true" :checked="data_value === true ? true : false" >
					 <text>是</text>
				 </radio>	
				 <radio value="false" :checked="data_value === false ? true : false"style="padding: 0 0 0 60rpx">
				 	<text>否</text>
				 </radio>	
			</radio-group>
		</div>
		<div v-else-if="type == '性别'">
			<radio-group @change="radiosex"  style="transform:scale(0.7);">
				<radio :value="item.name" :checked="data_value == item.name ? true : false" v-for="(item,index) in data" style="padding: 0 0 0 60rpx">
					 <text>{{item.name}}</text>
				 </radio>	
			</radio-group>
		</div>
		<div v-else-if="type == '单选'">
			<radio-group @change="radiochoice"  style="transform:scale(0.7);">
				<radio :value="item.name" :checked="item.name === '男' ? true : false" v-for="(item,index) in data" style="padding: 0 0 0 60rpx">
					 <text >{{item.name}}</text>
				 </radio>	
			</radio-group>
		</div>
		
		<popus ref="input_alert">
			<alertcenter :dataSorc="data" @row="row" @closes="closes" ></alertcenter>
		</popus>
		
	</view>
</template>

<script>
import kxTime from "@/components/kx-datetime/kx-datetime"	
import alertcenter from '@/pages/common/common/alert/alertcenter'	
import popus from '@/uni_modules/uni-popup/components/uni-popup/uni-popup'
export default {
	components: {
		alertcenter,
		popus,
		kxTime
	},
	props:{
		type: {
			default: ''
		},
		value: {
			default:''
		},
		values: {
			default: ''
		},
		code: {
			default: ''
		}
	},
	data(){
		return {
			data: [],
			data_value: '',
			dates: '',
		}
	},
	mounted() {
		this.data_value = this.value;
		if(this.code == 'getDate'){
			this.ouTime();
		}
		
		if(this.code == "gender"){
			let oun = [];
			this.data = [];
			if(this.values){
				oun = this.values.split(',')
				for (let i in oun) {
					this.data.push({name:oun[i]})
				}
				this.data_value = this.value;
			}
		}
		
		if(this.type == '单选'){
			let oun = [];
			this.data = [];
			if(this.values){
				oun = this.values.split(',')
				for (let i in oun) {
					this.data.push({name:oun[i]})
				}
			}
		}
	},
	methods:{
		inputalert(){
			let oun = [];
			this.data = [];
			if(this.values){
				oun = this.values.split(',')
				for (let i in oun) {
					this.data.push({name:oun[i]})
				}
			}
			this.$refs.input_alert.open('bottom')
		},
		
		inputserch(){
			let oun = [];
			this.data = [];
			if(this.values){
				oun = this.values
				for (let i in oun) {
					this.data.push({name:oun[i].title,id:oun[i].key})
				}
			}
			this.$refs.input_alert.open('bottom')
		},
		// 获取弹出类容
		row(val){
			this.data_value = val.name;
			if(val.id){ //搜索选择
				this.$emit('user_alert',{value:this.data_value,code:this.code,id:val.id})
			}else{
				this.$emit('user_alert',{value:this.data_value,code:this.code})
			}
			this.$refs.input_alert.close();
		},
		// 获取输入框内容
		text_value(val){
			let user_text = {code:this.code,value:val.detail.value}
			this.$emit('user_alert',user_text)
		},
		
		// 获取是否
		radioTrue(val){
			console.log(val)
			let user_text = {code:this.code,value:val.detail.value}
			this.$emit('user_alert',user_text)
		},
		
		// 获取性别
		radiosex(val){
			console.log(val)
			let user_text = {code:this.code,value:val.detail.value}
			this.$emit('user_alert',user_text)
		},
		
		// 获取单选
		radiochoice(val){
			console.log(val)
			let user_text = {code:this.code,value:val.detail.value}
			this.$emit('user_alert',user_text)
		},
		
		// 关闭弹出
		closes(){
			this.$refs.input_alert.close();
		},
		// 获取时间
		datetime(v){
			this.data_value = v.substr(0,10);
			if(this.code == 'getDate'){
				let user_text = {code:this.code,value:v.substr(0,10)}
				this.$emit('user_alert',user_text)
			}else{
				let user_text = {code:this.code,value:v.substr(0,10)}
				this.$emit('user_alert',user_text)
			}
		},

		// 获取默认时间
		ouTime(){
			var date =new Date();
			var year = date.getFullYear();        //年 ,从 Date 对象以四位数字返回年份
			var month = date.getMonth() + 1;      //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
			var day = date.getDate();             //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
			
			var hours = date.getHours();          //小时 ,返回 Date 对象的小时 (0 ~ 23)
			var minutes = date.getMinutes();      //分钟 ,返回 Date 对象的分钟 (0 ~ 59)
			var seconds = date.getSeconds();      //秒 ,返回 Date 对象的秒数 (0 ~ 59)   
			
			//获取当前系统时间  
			if(month < 10){
				month = 0 + String(month);
			}
			if(day < 10){
				day = 0 + String(day);
			}
			if(hours < 10){
				hours = 0 + String(hours);
			}
			if(minutes < 10){
				minutes = 0 + String(minutes);
			}
			// console.log(hours)
			var currentDate = year + "-" + month + "-" + day ;
			this.date = currentDate;
			this.cDate = currentDate;
			this.startdate =String(year);
			this.data_value = currentDate;
		}
		
	}
}
</script>

<style scoped lang="scss">
	input {
		width: 90%;
	}
	
</style>
